#!/bin/env bash
# 实例文件 chkpath.1
# 检查$PATH，查找人皆可写的目录或丢失的目录

exit_code=0

for dir in ${PATH//:/ }; do
    [ -L "$dir" ] && printf "%b" "symlink,"
    if [ ! -d "$dir" ]; then
        printf "%b" "missing\t\t"
        (( exit_code++ ))
    elif [ -n "$(ls -lLd $dir|grep '^d.......w.  ')" ]; then
        printf "%b" "world writable\t"
        (( exit_code++ ))
    else
        printf "%b" "ok\t\t"
    fi
    printf "%b\n" $dir
done
exit $exit_code
